package com.hnfnu.service.impl;

import com.hnfnu.protocol.dto.DisburseDTO;
import com.hnfnu.entity.Disburse;
import com.hnfnu.protocol.param.DisburseProgressParam;
import com.hnfnu.protocol.vo.ProjectDisburseProgressVO;
import com.hnfnu.service.BaseService;
import com.hnfnu.service.DisburseService;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class DisburseServiceImpl extends BaseService implements DisburseService {
    @Override
    public Boolean insertDisburse(Disburse disburse) {
        disburse.setTime(new Date());
        return disburseMapper.insert(disburse);
    }

    @Override
    public List<DisburseDTO> getDisburses() {
        return disburseMapper.list();
    }

    @Override
    public List<ProjectDisburseProgressVO> getDisbursesProgress(Integer projectId) {
        return disburseMapper.listProgress(projectId);
    }

    @Override
    public Boolean insertDisbursesProgress(DisburseProgressParam progressParam) {
        Integer projectId = progressParam.getProjectId();
        Double amount = disburseMapper.getAmountByProjectId(projectId);

        Disburse disburse = new Disburse();
        disburse.setProjectId(projectId);
        disburse.setAmount(amount);
        disburse.setAddress(progressParam.getAddress());
        disburse.setTime(progressParam.getTime());
        disburse.setDescription(progressParam.getDescription());
        disburse.setProgress(progressParam.getProgress());

        return disburseMapper.insert(disburse);
    }

    @Override
    public List<DisburseDTO> getDisbursesByProjectId(Integer projectId) {
        return disburseMapper.listByProjectId(projectId);
    }

    @Override
    public Double getTotalDisburse() {
        return disburseMapper.getTotalDisburse();
    }


}
